/*
 * PtrClassicAutoFrameLayout.java
 * business
 *
 * Created by ChenTao on 2017/5/23.
 *
 * Copyright (c) 2017年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.widget.view;

import android.content.Context;
import android.util.AttributeSet;

import in.srain.cube.views.ptr.PtrClassicDefaultHeader;
import in.srain.cube.views.ptr.PtrFrameLayout;

/**
 * 具备下拉位置回掉的  PtrClassicFrameLayout
 * <p>
 * Created by ChenTao(chentao7v@gmail.com) on 2017/5/23 0023 17:31
 */
public class PtrClassicAutoFrameLayout extends PtrFrameLayout {

    private PtrClassicAutoHeader mPtrClassicHeader;

    public PtrClassicAutoFrameLayout(Context context) {
        super(context);
        initViews();
    }

    public PtrClassicAutoFrameLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        initViews();
    }

    public PtrClassicAutoFrameLayout(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        initViews();
    }

    private void initViews() {
        mPtrClassicHeader = new PtrClassicAutoHeader(getContext());
        setHeaderView(mPtrClassicHeader);
        addPtrUIHandler(mPtrClassicHeader);
    }

    public PtrClassicDefaultHeader getHeader() {
        return mPtrClassicHeader;
    }

    /**
     * Specify the last update time by this key string
     */
    public void setLastUpdateTimeKey(String key) {
        if (mPtrClassicHeader != null) {
            mPtrClassicHeader.setLastUpdateTimeKey(key);
        }
    }

    /**
     * Using an object to specify the last update time.
     */
    public void setLastUpdateTimeRelateObject(Object object) {
        if (mPtrClassicHeader != null) {
            mPtrClassicHeader.setLastUpdateTimeRelateObject(object);
        }
    }

    public void setOnUIPositionChangeListener(PtrClassicAutoHeader.OnUIPositionChangeListener listener) {
        mPtrClassicHeader.setOnUIPositionChangeListener(listener);
    }
}
